package UseString.demo04;

import java.util.Scanner;

public class Practice01 {
    public static void main(String[] args) {
        // 1.长度不能大于9,只能输入数字，
        // 2.罗马和数字进行转换
        Scanner sc = new Scanner(System.in);
        String str;
        while (true){
            System.out.println("请输入数字");
            str = sc.next();
            boolean flag = checkString(str);
            if(flag){
                // 字符转换
                break;
            }else {
                System.out.println("请输入正确的格式");
                continue;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            int number = c -48;
            String s = changeLuomaMethod01(number);
            sb.append(s);
        }
        System.out.println(sb);

    }
    // 输入校验
    public static boolean checkString(String str){
        // 长度不能大于9
        if(str.length() > 9){
            return false;
        }
        // 只能输入数字
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if(c<'0' || c>'9'){
                return false;
            }
        }
        return true;
    }
    // 罗马数组转换方式1
    public static String changeLuomaMethod01(int i){
        String[] arr = {"","Ⅰ","Ⅱ","Ⅲ","Ⅳ","Ⅴ","Ⅵ","Ⅶ","Ⅷ","Ⅸ"};
        return arr[i];
    }
    // 罗马数组转换方式2
    public static String changeLuomaMethod02(char c){
        String str;
        switch (c){
            case '0'-> str = "";
            case '1'-> str = "Ⅰ";
            case '2'-> str = "Ⅱ";
            case '3'-> str = "Ⅲ";
            case '4'-> str = "Ⅳ";
            case '5'-> str = "Ⅴ";
            case '6'-> str = "Ⅵ";
            case '7'-> str = "Ⅶ";
            case '8'-> str = "Ⅷ";
            case '9'-> str = "Ⅸ";
            default -> str = "";
            }
            return str;
        }
}
